package cn.wuweixiang.springbootdemo.config;

import cn.wuweixiang.springbootdemo.condition.LinuxCondition;
import cn.wuweixiang.springbootdemo.condition.WindowsCondition;
import cn.wuweixiang.springbootdemo.service.ListService;
import cn.wuweixiang.springbootdemo.service.impl.LinuxListServiceImpl;
import cn.wuweixiang.springbootdemo.service.impl.WindowsListServiceImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;

/**
 * ConditionalConfig
 *
 * @author weixiang.wu
 * @date 2018 -08-22 15:55
 */
public class ConditionalConfig {

	/**
	 * 使用@Conditional注解，符合Linux条件就实例化LinuxListService
	 *
	 * @return the list service
	 */
	@Bean
	@Conditional(LinuxCondition.class)
	public ListService linuxListService() {
		return new LinuxListServiceImpl();
	}

	/**
	 * 使用@Conditional注解，符合Windows条件就实例化WindowsListService
	 *
	 * @return the list service
	 */
	@Bean
	@Conditional(WindowsCondition.class)
	public ListService windowsListService() {
		return new WindowsListServiceImpl();
	}

}
